<?php
	// Lấy mã sách từ thanh địa chỉ
	$MaHocSinh = $_GET['mhs'];
	$MaMonHoc = $_GET['mmh'];
	$diemhk = new diemhkbs();
	$diemhk->MaHocSinh = $MaHocSinh;
	$diemhk->MaMonHoc = $MaMonHoc;
	$danhsach = $diemhk->GetList();
	
?>
<form id="FormSua" action='<?php echo "diemhk-xoa-".$MaHocSinh."-".$MaMonHoc."";?>' method="post">
	<input type="hidden" value="<?php echo $MaHocSinh; ?>" name="MaHocSinh" />
    <input type="hidden" value="<?php echo $MaMonHoc ?>" name="MaMonHoc" />
	<table class="Form">
		<tr>
			<td>Năm học:</td>
			<td>
            <select name="NamHoc" class="required">
			<?php
				$namhoc = new namhocbs();
				$dmnamhoc = $namhoc->GetListNamHoc();
				
				for($i = 0; $i < count($dmnamhoc); $i++)
				{       
					if($dmnamhoc[$i]['NamHoc'] == $danhsach[0]['NamHoc'])
						echo "<option value='{$dmnamhoc[$i]['NamHoc']}' selected='selected' >{$dmnamhoc[$i]['NamHoc']}</option>";
					else
						echo "<option value='{$dmnamhoc[$i]['NamHoc']}'>{$dmnamhoc[$i]['NamHoc']}</option>";
				}
			?>
            </select>
                <span class="requirefield">*</span></td>
		</tr>
        <tr>
			<td>Học kỳ:</td>
			<td>
            <select name="HocKy" class="required">
			<?php
				$namhoc1 = new namhocbs();
				$dmnamhoc1 = $namhoc1->GetList();
				
				for($i = 0; $i < count($dmnamhoc1); $i++)
				{       
					if($dmnamhoc1[$i]['HocKy'] == $danhsach[0]['HocKy'])
						echo "<option value='{$dmnamhoc1[$i]['HocKy']}' selected='selected'>{$dmnamhoc1[$i]['HocKy']}</option>";
					else
						echo "<option value='{$dmnamhoc1[$i]['HocKy']}'>{$dmnamhoc1[$i]['HocKy']}</option>";
				}
			?>
            </select>
                <span class="requirefield">*</span></td>
		</tr>
	</table>
	<p class="GhiChuBatBuoc">(*): Trường bắt buộc phải nhập thông tin.</p>
	<input type="submit" value="Cập nhật vào CSDL" name="xoa" />
</form>
<?php
	if(isset($_POST['xoa']))
	{
		$HocKy = $_POST['HocKy'];
		$NamHoc = $_POST['NamHoc'];
		$diem = new diemhkbs();
		$diem->MaHocSinh = $MaHocSinh;
		$diem->MaMonHoc = $MaMonHoc;
		$diem->HocKy = $HocKy;
		$diem->NamHoc = $NamHoc;
		$kq = $diem->Delete();
		if($kq)
		{
			header("Location: hocsinh-diemhk-". $MaHocSinh."");
		}
		else
		{
			ThongBaoLoi("Xóa thất bại");
		}
	}
?>